<HTML>
<BODY BGCOLOR="white">
<PRE>
<FONT color="green">001</FONT>    /*<a name="line.1"></a>
<FONT color="green">002</FONT>     * Licensed to the Apache Software Foundation (ASF) under one or more<a name="line.2"></a>
<FONT color="green">003</FONT>     * contributor license agreements.  See the NOTICE file distributed with<a name="line.3"></a>
<FONT color="green">004</FONT>     * this work for additional information regarding copyright ownership.<a name="line.4"></a>
<FONT color="green">005</FONT>     * The ASF licenses this file to You under the Apache License, Version 2.0<a name="line.5"></a>
<FONT color="green">006</FONT>     * (the "License"); you may not use this file except in compliance with<a name="line.6"></a>
<FONT color="green">007</FONT>     * the License.  You may obtain a copy of the License at<a name="line.7"></a>
<FONT color="green">008</FONT>     *<a name="line.8"></a>
<FONT color="green">009</FONT>     *      http://www.apache.org/licenses/LICENSE-2.0<a name="line.9"></a>
<FONT color="green">010</FONT>     *<a name="line.10"></a>
<FONT color="green">011</FONT>     * Unless required by applicable law or agreed to in writing, software<a name="line.11"></a>
<FONT color="green">012</FONT>     * distributed under the License is distributed on an "AS IS" BASIS,<a name="line.12"></a>
<FONT color="green">013</FONT>     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<a name="line.13"></a>
<FONT color="green">014</FONT>     * See the License for the specific language governing permissions and<a name="line.14"></a>
<FONT color="green">015</FONT>     * limitations under the License.<a name="line.15"></a>
<FONT color="green">016</FONT>     */<a name="line.16"></a>
<FONT color="green">017</FONT>    package org.apache.commons.codec.digest;<a name="line.17"></a>
<FONT color="green">018</FONT>    <a name="line.18"></a>
<FONT color="green">019</FONT>    import java.util.Random;<a name="line.19"></a>
<FONT color="green">020</FONT>    <a name="line.20"></a>
<FONT color="green">021</FONT>    import org.apache.commons.codec.Charsets;<a name="line.21"></a>
<FONT color="green">022</FONT>    <a name="line.22"></a>
<FONT color="green">023</FONT>    /**<a name="line.23"></a>
<FONT color="green">024</FONT>     * Unix crypt(3) algorithm implementation.<a name="line.24"></a>
<FONT color="green">025</FONT>     * &lt;p&gt;<a name="line.25"></a>
<FONT color="green">026</FONT>     * This class only implements the traditional 56 bit DES based algorithm. Please use DigestUtils.crypt() for a method<a name="line.26"></a>
<FONT color="green">027</FONT>     * that distinguishes between all the algorithms supported in the current glibc's crypt().<a name="line.27"></a>
<FONT color="green">028</FONT>     * &lt;p&gt;<a name="line.28"></a>
<FONT color="green">029</FONT>     * The Java implementation was taken from the JetSpeed Portal project (see<a name="line.29"></a>
<FONT color="green">030</FONT>     * org.apache.jetspeed.services.security.ldap.UnixCrypt).<a name="line.30"></a>
<FONT color="green">031</FONT>     * &lt;p&gt;<a name="line.31"></a>
<FONT color="green">032</FONT>     * This class is slightly incompatible if the given salt contains characters that are not part of the allowed range<a name="line.32"></a>
<FONT color="green">033</FONT>     * [a-zA-Z0-9./].<a name="line.33"></a>
<FONT color="green">034</FONT>     * &lt;p&gt;<a name="line.34"></a>
<FONT color="green">035</FONT>     * This class is immutable and thread-safe.<a name="line.35"></a>
<FONT color="green">036</FONT>     *<a name="line.36"></a>
<FONT color="green">037</FONT>     * @version $Id: UnixCrypt.java 1429868 2013-01-07 16:08:05Z ggregory $<a name="line.37"></a>
<FONT color="green">038</FONT>     * @since 1.7<a name="line.38"></a>
<FONT color="green">039</FONT>     */<a name="line.39"></a>
<FONT color="green">040</FONT>    public class UnixCrypt {<a name="line.40"></a>
<FONT color="green">041</FONT>    <a name="line.41"></a>
<FONT color="green">042</FONT>        private static final int CON_SALT[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,<a name="line.42"></a>
<FONT color="green">043</FONT>                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 5, 6,<a name="line.43"></a>
<FONT color="green">044</FONT>                7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,<a name="line.44"></a>
<FONT color="green">045</FONT>                34, 35, 36, 37, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,<a name="line.45"></a>
<FONT color="green">046</FONT>                54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 0, 0, 0, 0, 0 };<a name="line.46"></a>
<FONT color="green">047</FONT>    <a name="line.47"></a>
<FONT color="green">048</FONT>        private static final int COV2CHAR[] = { 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70,<a name="line.48"></a>
<FONT color="green">049</FONT>                71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102,<a name="line.49"></a>
<FONT color="green">050</FONT>                103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122 };<a name="line.50"></a>
<FONT color="green">051</FONT>    <a name="line.51"></a>
<FONT color="green">052</FONT>        private static final char SALT_CHARS[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"<a name="line.52"></a>
<FONT color="green">053</FONT>                .toCharArray();<a name="line.53"></a>
<FONT color="green">054</FONT>    <a name="line.54"></a>
<FONT color="green">055</FONT>        private static final boolean SHIFT2[] = { false, false, true, true, true, true, true, true, false, true, true,<a name="line.55"></a>
<FONT color="green">056</FONT>                true, true, true, true, false };<a name="line.56"></a>
<FONT color="green">057</FONT>    <a name="line.57"></a>
<FONT color="green">058</FONT>        private static final int SKB[][] = {<a name="line.58"></a>
<FONT color="green">059</FONT>                { 0, 16, 0x20000000, 0x20000010, 0x10000, 0x10010, 0x20010000, 0x20010010, 2048, 2064, 0x20000800,<a name="line.59"></a>
<FONT color="green">060</FONT>                        0x20000810, 0x10800, 0x10810, 0x20010800, 0x20010810, 32, 48, 0x20000020, 0x20000030, 0x10020,<a name="line.60"></a>
<FONT color="green">061</FONT>                        0x10030, 0x20010020, 0x20010030, 2080, 2096, 0x20000820, 0x20000830, 0x10820, 0x10830, 0x20010820,<a name="line.61"></a>
<FONT color="green">062</FONT>                        0x20010830, 0x80000, 0x80010, 0x20080000, 0x20080010, 0x90000, 0x90010, 0x20090000, 0x20090010,<a name="line.62"></a>
<FONT color="green">063</FONT>                        0x80800, 0x80810, 0x20080800, 0x20080810, 0x90800, 0x90810, 0x20090800, 0x20090810, 0x80020,<a name="line.63"></a>
<FONT color="green">064</FONT>                        0x80030, 0x20080020, 0x20080030, 0x90020, 0x90030, 0x20090020, 0x20090030, 0x80820, 0x80830,<a name="line.64"></a>
<FONT color="green">065</FONT>                        0x20080820, 0x20080830, 0x90820, 0x90830, 0x20090820, 0x20090830 },<a name="line.65"></a>
<FONT color="green">066</FONT>                { 0, 0x2000000, 8192, 0x2002000, 0x200000, 0x2200000, 0x202000, 0x2202000, 4, 0x2000004, 8196, 0x2002004,<a name="line.66"></a>
<FONT color="green">067</FONT>                        0x200004, 0x2200004, 0x202004, 0x2202004, 1024, 0x2000400, 9216, 0x2002400, 0x200400, 0x2200400,<a name="line.67"></a>
<FONT color="green">068</FONT>                        0x202400, 0x2202400, 1028, 0x2000404, 9220, 0x2002404, 0x200404, 0x2200404, 0x202404, 0x2202404,<a name="line.68"></a>
<FONT color="green">069</FONT>                        0x10000000, 0x12000000, 0x10002000, 0x12002000, 0x10200000, 0x12200000, 0x10202000, 0x12202000,<a name="line.69"></a>
<FONT color="green">070</FONT>                        0x10000004, 0x12000004, 0x10002004, 0x12002004, 0x10200004, 0x12200004, 0x10202004, 0x12202004,<a name="line.70"></a>
<FONT color="green">071</FONT>                        0x10000400, 0x12000400, 0x10002400, 0x12002400, 0x10200400, 0x12200400, 0x10202400, 0x12202400,<a name="line.71"></a>
<FONT color="green">072</FONT>                        0x10000404, 0x12000404, 0x10002404, 0x12002404, 0x10200404, 0x12200404, 0x10202404, 0x12202404 },<a name="line.72"></a>
<FONT color="green">073</FONT>                { 0, 1, 0x40000, 0x40001, 0x1000000, 0x1000001, 0x1040000, 0x1040001, 2, 3, 0x40002, 0x40003, 0x1000002,<a name="line.73"></a>
<FONT color="green">074</FONT>                        0x1000003, 0x1040002, 0x1040003, 512, 513, 0x40200, 0x40201, 0x1000200, 0x1000201, 0x1040200,<a name="line.74"></a>
<FONT color="green">075</FONT>                        0x1040201, 514, 515, 0x40202, 0x40203, 0x1000202, 0x1000203, 0x1040202, 0x1040203, 0x8000000,<a name="line.75"></a>
<FONT color="green">076</FONT>                        0x8000001, 0x8040000, 0x8040001, 0x9000000, 0x9000001, 0x9040000, 0x9040001, 0x8000002, 0x8000003,<a name="line.76"></a>
<FONT color="green">077</FONT>                        0x8040002, 0x8040003, 0x9000002, 0x9000003, 0x9040002, 0x9040003, 0x8000200, 0x8000201, 0x8040200,<a name="line.77"></a>
<FONT color="green">078</FONT>                        0x8040201, 0x9000200, 0x9000201, 0x9040200, 0x9040201, 0x8000202, 0x8000203, 0x8040202, 0x8040203,<a name="line.78"></a>
<FONT color="green">079</FONT>                        0x9000202, 0x9000203, 0x9040202, 0x9040203 },<a name="line.79"></a>
<FONT color="green">080</FONT>                { 0, 0x100000, 256, 0x100100, 8, 0x100008, 264, 0x100108, 4096, 0x101000, 4352, 0x101100, 4104, 0x101008,<a name="line.80"></a>
<FONT color="green">081</FONT>                        4360, 0x101108, 0x4000000, 0x4100000, 0x4000100, 0x4100100, 0x4000008, 0x4100008, 0x4000108,<a name="line.81"></a>
<FONT color="green">082</FONT>                        0x4100108, 0x4001000, 0x4101000, 0x4001100, 0x4101100, 0x4001008, 0x4101008, 0x4001108, 0x4101108,<a name="line.82"></a>
<FONT color="green">083</FONT>                        0x20000, 0x120000, 0x20100, 0x120100, 0x20008, 0x120008, 0x20108, 0x120108, 0x21000, 0x121000,<a name="line.83"></a>
<FONT color="green">084</FONT>                        0x21100, 0x121100, 0x21008, 0x121008, 0x21108, 0x121108, 0x4020000, 0x4120000, 0x4020100,<a name="line.84"></a>
<FONT color="green">085</FONT>                        0x4120100, 0x4020008, 0x4120008, 0x4020108, 0x4120108, 0x4021000, 0x4121000, 0x4021100, 0x4121100,<a name="line.85"></a>
<FONT color="green">086</FONT>                        0x4021008, 0x4121008, 0x4021108, 0x4121108 },<a name="line.86"></a>
<FONT color="green">087</FONT>                { 0, 0x10000000, 0x10000, 0x10010000, 4, 0x10000004, 0x10004, 0x10010004, 0x20000000, 0x30000000,<a name="line.87"></a>
<FONT color="green">088</FONT>                        0x20010000, 0x30010000, 0x20000004, 0x30000004, 0x20010004, 0x30010004, 0x100000, 0x10100000,<a name="line.88"></a>
<FONT color="green">089</FONT>                        0x110000, 0x10110000, 0x100004, 0x10100004, 0x110004, 0x10110004, 0x20100000, 0x30100000,<a name="line.89"></a>
<FONT color="green">090</FONT>                        0x20110000, 0x30110000, 0x20100004, 0x30100004, 0x20110004, 0x30110004, 4096, 0x10001000, 0x11000,<a name="line.90"></a>
<FONT color="green">091</FONT>                        0x10011000, 4100, 0x10001004, 0x11004, 0x10011004, 0x20001000, 0x30001000, 0x20011000, 0x30011000,<a name="line.91"></a>
<FONT color="green">092</FONT>                        0x20001004, 0x30001004, 0x20011004, 0x30011004, 0x101000, 0x10101000, 0x111000, 0x10111000,<a name="line.92"></a>
<FONT color="green">093</FONT>                        0x101004, 0x10101004, 0x111004, 0x10111004, 0x20101000, 0x30101000, 0x20111000, 0x30111000,<a name="line.93"></a>
<FONT color="green">094</FONT>                        0x20101004, 0x30101004, 0x20111004, 0x30111004 },<a name="line.94"></a>
<FONT color="green">095</FONT>                { 0, 0x8000000, 8, 0x8000008, 1024, 0x8000400, 1032, 0x8000408, 0x20000, 0x8020000, 0x20008, 0x8020008,<a name="line.95"></a>
<FONT color="green">096</FONT>                        0x20400, 0x8020400, 0x20408, 0x8020408, 1, 0x8000001, 9, 0x8000009, 1025, 0x8000401, 1033,<a name="line.96"></a>
<FONT color="green">097</FONT>                        0x8000409, 0x20001, 0x8020001, 0x20009, 0x8020009, 0x20401, 0x8020401, 0x20409, 0x8020409,<a name="line.97"></a>
<FONT color="green">098</FONT>                        0x2000000, 0xa000000, 0x2000008, 0xa000008, 0x2000400, 0xa000400, 0x2000408, 0xa000408, 0x2020000,<a name="line.98"></a>
<FONT color="green">099</FONT>                        0xa020000, 0x2020008, 0xa020008, 0x2020400, 0xa020400, 0x2020408, 0xa020408, 0x2000001, 0xa000001,<a name="line.99"></a>
<FONT color="green">100</FONT>                        0x2000009, 0xa000009, 0x2000401, 0xa000401, 0x2000409, 0xa000409, 0x2020001, 0xa020001, 0x2020009,<a name="line.100"></a>
<FONT color="green">101</FONT>                        0xa020009, 0x2020401, 0xa020401, 0x2020409, 0xa020409 },<a name="line.101"></a>
<FONT color="green">102</FONT>                { 0, 256, 0x80000, 0x80100, 0x1000000, 0x1000100, 0x1080000, 0x1080100, 16, 272, 0x80010, 0x80110,<a name="line.102"></a>
<FONT color="green">103</FONT>                        0x1000010, 0x1000110, 0x1080010, 0x1080110, 0x200000, 0x200100, 0x280000, 0x280100, 0x1200000,<a name="line.103"></a>
<FONT color="green">104</FONT>                        0x1200100, 0x1280000, 0x1280100, 0x200010, 0x200110, 0x280010, 0x280110, 0x1200010, 0x1200110,<a name="line.104"></a>
<FONT color="green">105</FONT>                        0x1280010, 0x1280110, 512, 768, 0x80200, 0x80300, 0x1000200, 0x1000300, 0x1080200, 0x1080300, 528,<a name="line.105"></a>
<FONT color="green">106</FONT>                        784, 0x80210, 0x80310, 0x1000210, 0x1000310, 0x1080210, 0x1080310, 0x200200, 0x200300, 0x280200,<a name="line.106"></a>
<FONT color="green">107</FONT>                        0x280300, 0x1200200, 0x1200300, 0x1280200, 0x1280300, 0x200210, 0x200310, 0x280210, 0x280310,<a name="line.107"></a>
<FONT color="green">108</FONT>                        0x1200210, 0x1200310, 0x1280210, 0x1280310 },<a name="line.108"></a>
<FONT color="green">109</FONT>                { 0, 0x4000000, 0x40000, 0x4040000, 2, 0x4000002, 0x40002, 0x4040002, 8192, 0x4002000, 0x42000, 0x4042000,<a name="line.109"></a>
<FONT color="green">110</FONT>                        8194, 0x4002002, 0x42002, 0x4042002, 32, 0x4000020, 0x40020, 0x4040020, 34, 0x4000022, 0x40022,<a name="line.110"></a>
<FONT color="green">111</FONT>                        0x4040022, 8224, 0x4002020, 0x42020, 0x4042020, 8226, 0x4002022, 0x42022, 0x4042022, 2048,<a name="line.111"></a>
<FONT color="green">112</FONT>                        0x4000800, 0x40800, 0x4040800, 2050, 0x4000802, 0x40802, 0x4040802, 10240, 0x4002800, 0x42800,<a name="line.112"></a>
<FONT color="green">113</FONT>                        0x4042800, 10242, 0x4002802, 0x42802, 0x4042802, 2080, 0x4000820, 0x40820, 0x4040820, 2082,<a name="line.113"></a>
<FONT color="green">114</FONT>                        0x4000822, 0x40822, 0x4040822, 10272, 0x4002820, 0x42820, 0x4042820, 10274, 0x4002822, 0x42822,<a name="line.114"></a>
<FONT color="green">115</FONT>                        0x4042822 } };<a name="line.115"></a>
<FONT color="green">116</FONT>    <a name="line.116"></a>
<FONT color="green">117</FONT>        private static final int SPTRANS[][] = {<a name="line.117"></a>
<FONT color="green">118</FONT>                { 0x820200, 0x20000, 0x80800000, 0x80820200, 0x800000, 0x80020200, 0x80020000, 0x80800000, 0x80020200,<a name="line.118"></a>
<FONT color="green">119</FONT>                        0x820200, 0x820000, 0x80000200, 0x80800200, 0x800000, 0, 0x80020000, 0x20000, 0x80000000,<a name="line.119"></a>
<FONT color="green">120</FONT>                        0x800200, 0x20200, 0x80820200, 0x820000, 0x80000200, 0x800200, 0x80000000, 512, 0x20200,<a name="line.120"></a>
<FONT color="green">121</FONT>                        0x80820000, 512, 0x80800200, 0x80820000, 0, 0, 0x80820200, 0x800200, 0x80020000, 0x820200,<a name="line.121"></a>
<FONT color="green">122</FONT>                        0x20000, 0x80000200, 0x800200, 0x80820000, 512, 0x20200, 0x80800000, 0x80020200, 0x80000000,<a name="line.122"></a>
<FONT color="green">123</FONT>                        0x80800000, 0x820000, 0x80820200, 0x20200, 0x820000, 0x80800200, 0x800000, 0x80000200, 0x80020000,<a name="line.123"></a>
<FONT color="green">124</FONT>                        0, 0x20000, 0x800000, 0x80800200, 0x820200, 0x80000000, 0x80820000, 512, 0x80020200 },<a name="line.124"></a>
<FONT color="green">125</FONT>                { 0x10042004, 0, 0x42000, 0x10040000, 0x10000004, 8196, 0x10002000, 0x42000, 8192, 0x10040004, 4,<a name="line.125"></a>
<FONT color="green">126</FONT>                        0x10002000, 0x40004, 0x10042000, 0x10040000, 4, 0x40000, 0x10002004, 0x10040004, 8192, 0x42004,<a name="line.126"></a>
<FONT color="green">127</FONT>                        0x10000000, 0, 0x40004, 0x10002004, 0x42004, 0x10042000, 0x10000004, 0x10000000, 0x40000, 8196,<a name="line.127"></a>
<FONT color="green">128</FONT>                        0x10042004, 0x40004, 0x10042000, 0x10002000, 0x42004, 0x10042004, 0x40004, 0x10000004, 0,<a name="line.128"></a>
<FONT color="green">129</FONT>                        0x10000000, 8196, 0x40000, 0x10040004, 8192, 0x10000000, 0x42004, 0x10002004, 0x10042000, 8192, 0,<a name="line.129"></a>
<FONT color="green">130</FONT>                        0x10000004, 4, 0x10042004, 0x42000, 0x10040000, 0x10040004, 0x40000, 8196, 0x10002000, 0x10002004,<a name="line.130"></a>
<FONT color="green">131</FONT>                        4, 0x10040000, 0x42000 },<a name="line.131"></a>
<FONT color="green">132</FONT>                { 0x41000000, 0x1010040, 64, 0x41000040, 0x40010000, 0x1000000, 0x41000040, 0x10040, 0x1000040, 0x10000,<a name="line.132"></a>
<FONT color="green">133</FONT>                        0x1010000, 0x40000000, 0x41010040, 0x40000040, 0x40000000, 0x41010000, 0, 0x40010000, 0x1010040,<a name="line.133"></a>
<FONT color="green">134</FONT>                        64, 0x40000040, 0x41010040, 0x10000, 0x41000000, 0x41010000, 0x1000040, 0x40010040, 0x1010000,<a name="line.134"></a>
<FONT color="green">135</FONT>                        0x10040, 0, 0x1000000, 0x40010040, 0x1010040, 64, 0x40000000, 0x10000, 0x40000040, 0x40010000,<a name="line.135"></a>
<FONT color="green">136</FONT>                        0x1010000, 0x41000040, 0, 0x1010040, 0x10040, 0x41010000, 0x40010000, 0x1000000, 0x41010040,<a name="line.136"></a>
<FONT color="green">137</FONT>                        0x40000000, 0x40010040, 0x41000000, 0x1000000, 0x41010040, 0x10000, 0x1000040, 0x41000040,<a name="line.137"></a>
<FONT color="green">138</FONT>                        0x10040, 0x1000040, 0, 0x41010000, 0x40000040, 0x41000000, 0x40010040, 64, 0x1010000 },<a name="line.138"></a>
<FONT color="green">139</FONT>                { 0x100402, 0x4000400, 2, 0x4100402, 0, 0x4100000, 0x4000402, 0x100002, 0x4100400, 0x4000002, 0x4000000,<a name="line.139"></a>
<FONT color="green">140</FONT>                        1026, 0x4000002, 0x100402, 0x100000, 0x4000000, 0x4100002, 0x100400, 1024, 2, 0x100400, 0x4000402,<a name="line.140"></a>
<FONT color="green">141</FONT>                        0x4100000, 1024, 1026, 0, 0x100002, 0x4100400, 0x4000400, 0x4100002, 0x4100402, 0x100000,<a name="line.141"></a>
<FONT color="green">142</FONT>                        0x4100002, 1026, 0x100000, 0x4000002, 0x100400, 0x4000400, 2, 0x4100000, 0x4000402, 0, 1024,<a name="line.142"></a>
<FONT color="green">143</FONT>                        0x100002, 0, 0x4100002, 0x4100400, 1024, 0x4000000, 0x4100402, 0x100402, 0x100000, 0x4100402, 2,<a name="line.143"></a>
<FONT color="green">144</FONT>                        0x4000400, 0x100402, 0x100002, 0x100400, 0x4100000, 0x4000402, 1026, 0x4000000, 0x4000002,<a name="line.144"></a>
<FONT color="green">145</FONT>                        0x4100400 },<a name="line.145"></a>
<FONT color="green">146</FONT>                { 0x2000000, 16384, 256, 0x2004108, 0x2004008, 0x2000100, 16648, 0x2004000, 16384, 8, 0x2000008, 16640,<a name="line.146"></a>
<FONT color="green">147</FONT>                        0x2000108, 0x2004008, 0x2004100, 0, 16640, 0x2000000, 16392, 264, 0x2000100, 16648, 0, 0x2000008,<a name="line.147"></a>
<FONT color="green">148</FONT>                        8, 0x2000108, 0x2004108, 16392, 0x2004000, 256, 264, 0x2004100, 0x2004100, 0x2000108, 16392,<a name="line.148"></a>
<FONT color="green">149</FONT>                        0x2004000, 16384, 8, 0x2000008, 0x2000100, 0x2000000, 16640, 0x2004108, 0, 16648, 0x2000000, 256,<a name="line.149"></a>
<FONT color="green">150</FONT>                        16392, 0x2000108, 256, 0, 0x2004108, 0x2004008, 0x2004100, 264, 16384, 16640, 0x2004008,<a name="line.150"></a>
<FONT color="green">151</FONT>                        0x2000100, 264, 8, 16648, 0x2004000, 0x2000008 },<a name="line.151"></a>
<FONT color="green">152</FONT>                { 0x20000010, 0x80010, 0, 0x20080800, 0x80010, 2048, 0x20000810, 0x80000, 2064, 0x20080810, 0x80800,<a name="line.152"></a>
<FONT color="green">153</FONT>                        0x20000000, 0x20000800, 0x20000010, 0x20080000, 0x80810, 0x80000, 0x20000810, 0x20080010, 0, 2048,<a name="line.153"></a>
<FONT color="green">154</FONT>                        16, 0x20080800, 0x20080010, 0x20080810, 0x20080000, 0x20000000, 2064, 16, 0x80800, 0x80810,<a name="line.154"></a>
<FONT color="green">155</FONT>                        0x20000800, 2064, 0x20000000, 0x20000800, 0x80810, 0x20080800, 0x80010, 0, 0x20000800, 0x20000000,<a name="line.155"></a>
<FONT color="green">156</FONT>                        2048, 0x20080010, 0x80000, 0x80010, 0x20080810, 0x80800, 16, 0x20080810, 0x80800, 0x80000,<a name="line.156"></a>
<FONT color="green">157</FONT>                        0x20000810, 0x20000010, 0x20080000, 0x80810, 0, 2048, 0x20000010, 0x20000810, 0x20080800,<a name="line.157"></a>
<FONT color="green">158</FONT>                        0x20080000, 2064, 16, 0x20080010 },<a name="line.158"></a>
<FONT color="green">159</FONT>                { 4096, 128, 0x400080, 0x400001, 0x401081, 4097, 4224, 0, 0x400000, 0x400081, 129, 0x401000, 1, 0x401080,<a name="line.159"></a>
<FONT color="green">160</FONT>                        0x401000, 129, 0x400081, 4096, 4097, 0x401081, 0, 0x400080, 0x400001, 4224, 0x401001, 4225,<a name="line.160"></a>
<FONT color="green">161</FONT>                        0x401080, 1, 4225, 0x401001, 128, 0x400000, 4225, 0x401000, 0x401001, 129, 4096, 128, 0x400000,<a name="line.161"></a>
<FONT color="green">162</FONT>                        0x401001, 0x400081, 4225, 4224, 0, 128, 0x400001, 1, 0x400080, 0, 0x400081, 0x400080, 4224, 129,<a name="line.162"></a>
<FONT color="green">163</FONT>                        4096, 0x401081, 0x400000, 0x401080, 1, 4097, 0x401081, 0x400001, 0x401080, 0x401000, 4097 },<a name="line.163"></a>
<FONT color="green">164</FONT>                { 0x8200020, 0x8208000, 32800, 0, 0x8008000, 0x200020, 0x8200000, 0x8208020, 32, 0x8000000, 0x208000,<a name="line.164"></a>
<FONT color="green">165</FONT>                        32800, 0x208020, 0x8008020, 0x8000020, 0x8200000, 32768, 0x208020, 0x200020, 0x8008000, 0x8208020,<a name="line.165"></a>
<FONT color="green">166</FONT>                        0x8000020, 0, 0x208000, 0x8000000, 0x200000, 0x8008020, 0x8200020, 0x200000, 32768, 0x8208000, 32,<a name="line.166"></a>
<FONT color="green">167</FONT>                        0x200000, 32768, 0x8000020, 0x8208020, 32800, 0x8000000, 0, 0x208000, 0x8200020, 0x8008020,<a name="line.167"></a>
<FONT color="green">168</FONT>                        0x8008000, 0x200020, 0x8208000, 32, 0x200020, 0x8008000, 0x8208020, 0x200000, 0x8200000,<a name="line.168"></a>
<FONT color="green">169</FONT>                        0x8000020, 0x208000, 32800, 0x8008020, 0x8200000, 32, 0x8208000, 0x208020, 0, 0x8000000,<a name="line.169"></a>
<FONT color="green">170</FONT>                        0x8200020, 32768, 0x208020 } };<a name="line.170"></a>
<FONT color="green">171</FONT>    <a name="line.171"></a>
<FONT color="green">172</FONT>        /**<a name="line.172"></a>
<FONT color="green">173</FONT>         * Generates a crypt(3) compatible hash using the DES algorithm.<a name="line.173"></a>
<FONT color="green">174</FONT>         * &lt;p&gt;<a name="line.174"></a>
<FONT color="green">175</FONT>         * As no salt is given, a random one will be used.<a name="line.175"></a>
<FONT color="green">176</FONT>         *<a name="line.176"></a>
<FONT color="green">177</FONT>         * @param original<a name="line.177"></a>
<FONT color="green">178</FONT>         *            plaintext password<a name="line.178"></a>
<FONT color="green">179</FONT>         * @return a 13 character string starting with the salt string<a name="line.179"></a>
<FONT color="green">180</FONT>         */<a name="line.180"></a>
<FONT color="green">181</FONT>        public static String crypt(final byte[] original) {<a name="line.181"></a>
<FONT color="green">182</FONT>            return crypt(original, null);<a name="line.182"></a>
<FONT color="green">183</FONT>        }<a name="line.183"></a>
<FONT color="green">184</FONT>    <a name="line.184"></a>
<FONT color="green">185</FONT>        /**<a name="line.185"></a>
<FONT color="green">186</FONT>         * Generates a crypt(3) compatible hash using the DES algorithm.<a name="line.186"></a>
<FONT color="green">187</FONT>         * &lt;p&gt;<a name="line.187"></a>
<FONT color="green">188</FONT>         * Using unspecified characters as salt results incompatible hash values.<a name="line.188"></a>
<FONT color="green">189</FONT>         *<a name="line.189"></a>
<FONT color="green">190</FONT>         * @param original<a name="line.190"></a>
<FONT color="green">191</FONT>         *            plaintext password<a name="line.191"></a>
<FONT color="green">192</FONT>         * @param salt<a name="line.192"></a>
<FONT color="green">193</FONT>         *            a two character string drawn from [a-zA-Z0-9./] or null for a random one<a name="line.193"></a>
<FONT color="green">194</FONT>         * @return a 13 character string starting with the salt string<a name="line.194"></a>
<FONT color="green">195</FONT>         * @throws IllegalArgumentException<a name="line.195"></a>
<FONT color="green">196</FONT>         *             if the salt does not match the allowed pattern<a name="line.196"></a>
<FONT color="green">197</FONT>         */<a name="line.197"></a>
<FONT color="green">198</FONT>        public static String crypt(final byte[] original, String salt) {<a name="line.198"></a>
<FONT color="green">199</FONT>            if (salt == null) {<a name="line.199"></a>
<FONT color="green">200</FONT>                final Random randomGenerator = new Random();<a name="line.200"></a>
<FONT color="green">201</FONT>                final int numSaltChars = SALT_CHARS.length;<a name="line.201"></a>
<FONT color="green">202</FONT>                salt = "" + SALT_CHARS[randomGenerator.nextInt(numSaltChars)] +<a name="line.202"></a>
<FONT color="green">203</FONT>                        SALT_CHARS[randomGenerator.nextInt(numSaltChars)];<a name="line.203"></a>
<FONT color="green">204</FONT>            } else if (!salt.matches("^[" + B64.B64T + "]{2,}$")) {<a name="line.204"></a>
<FONT color="green">205</FONT>                throw new IllegalArgumentException("Invalid salt value: " + salt);<a name="line.205"></a>
<FONT color="green">206</FONT>            }<a name="line.206"></a>
<FONT color="green">207</FONT>    <a name="line.207"></a>
<FONT color="green">208</FONT>            final StringBuilder buffer = new StringBuilder("             ");<a name="line.208"></a>
<FONT color="green">209</FONT>            final char charZero = salt.charAt(0);<a name="line.209"></a>
<FONT color="green">210</FONT>            final char charOne = salt.charAt(1);<a name="line.210"></a>
<FONT color="green">211</FONT>            buffer.setCharAt(0, charZero);<a name="line.211"></a>
<FONT color="green">212</FONT>            buffer.setCharAt(1, charOne);<a name="line.212"></a>
<FONT color="green">213</FONT>            final int eSwap0 = CON_SALT[charZero];<a name="line.213"></a>
<FONT color="green">214</FONT>            final int eSwap1 = CON_SALT[charOne] &lt;&lt; 4;<a name="line.214"></a>
<FONT color="green">215</FONT>            final byte key[] = new byte[8];<a name="line.215"></a>
<FONT color="green">216</FONT>            for (int i = 0; i &lt; key.length; i++) {<a name="line.216"></a>
<FONT color="green">217</FONT>                key[i] = 0;<a name="line.217"></a>
<FONT color="green">218</FONT>            }<a name="line.218"></a>
<FONT color="green">219</FONT>    <a name="line.219"></a>
<FONT color="green">220</FONT>            for (int i = 0; i &lt; key.length &amp;&amp; i &lt; original.length; i++) {<a name="line.220"></a>
<FONT color="green">221</FONT>                final int iChar = original[i];<a name="line.221"></a>
<FONT color="green">222</FONT>                key[i] = (byte) (iChar &lt;&lt; 1);<a name="line.222"></a>
<FONT color="green">223</FONT>            }<a name="line.223"></a>
<FONT color="green">224</FONT>    <a name="line.224"></a>
<FONT color="green">225</FONT>            final int schedule[] = desSetKey(key);<a name="line.225"></a>
<FONT color="green">226</FONT>            final int out[] = body(schedule, eSwap0, eSwap1);<a name="line.226"></a>
<FONT color="green">227</FONT>            final byte b[] = new byte[9];<a name="line.227"></a>
<FONT color="green">228</FONT>            intToFourBytes(out[0], b, 0);<a name="line.228"></a>
<FONT color="green">229</FONT>            intToFourBytes(out[1], b, 4);<a name="line.229"></a>
<FONT color="green">230</FONT>            b[8] = 0;<a name="line.230"></a>
<FONT color="green">231</FONT>            int i = 2;<a name="line.231"></a>
<FONT color="green">232</FONT>            int y = 0;<a name="line.232"></a>
<FONT color="green">233</FONT>            int u = 128;<a name="line.233"></a>
<FONT color="green">234</FONT>            for (; i &lt; 13; i++) {<a name="line.234"></a>
<FONT color="green">235</FONT>                int j = 0;<a name="line.235"></a>
<FONT color="green">236</FONT>                int c = 0;<a name="line.236"></a>
<FONT color="green">237</FONT>                for (; j &lt; 6; j++) {<a name="line.237"></a>
<FONT color="green">238</FONT>                    c &lt;&lt;= 1;<a name="line.238"></a>
<FONT color="green">239</FONT>                    if ((b[y] &amp; u) != 0) {<a name="line.239"></a>
<FONT color="green">240</FONT>                        c |= 0x1;<a name="line.240"></a>
<FONT color="green">241</FONT>                    }<a name="line.241"></a>
<FONT color="green">242</FONT>                    u &gt;&gt;&gt;= 1;<a name="line.242"></a>
<FONT color="green">243</FONT>                    if (u == 0) {<a name="line.243"></a>
<FONT color="green">244</FONT>                        y++;<a name="line.244"></a>
<FONT color="green">245</FONT>                        u = 128;<a name="line.245"></a>
<FONT color="green">246</FONT>                    }<a name="line.246"></a>
<FONT color="green">247</FONT>                    buffer.setCharAt(i, (char) COV2CHAR[c]);<a name="line.247"></a>
<FONT color="green">248</FONT>                }<a name="line.248"></a>
<FONT color="green">249</FONT>            }<a name="line.249"></a>
<FONT color="green">250</FONT>            return buffer.toString();<a name="line.250"></a>
<FONT color="green">251</FONT>        }<a name="line.251"></a>
<FONT color="green">252</FONT>    <a name="line.252"></a>
<FONT color="green">253</FONT>        /**<a name="line.253"></a>
<FONT color="green">254</FONT>         * Generates a crypt(3) compatible hash using the DES algorithm.<a name="line.254"></a>
<FONT color="green">255</FONT>         * &lt;p&gt;<a name="line.255"></a>
<FONT color="green">256</FONT>         * As no salt is given, a random one is used.<a name="line.256"></a>
<FONT color="green">257</FONT>         *<a name="line.257"></a>
<FONT color="green">258</FONT>         * @param original<a name="line.258"></a>
<FONT color="green">259</FONT>         *            plaintext password<a name="line.259"></a>
<FONT color="green">260</FONT>         * @return a 13 character string starting with the salt string<a name="line.260"></a>
<FONT color="green">261</FONT>         */<a name="line.261"></a>
<FONT color="green">262</FONT>        public static String crypt(final String original) {<a name="line.262"></a>
<FONT color="green">263</FONT>            return crypt(original.getBytes(Charsets.UTF_8));<a name="line.263"></a>
<FONT color="green">264</FONT>        }<a name="line.264"></a>
<FONT color="green">265</FONT>    <a name="line.265"></a>
<FONT color="green">266</FONT>        /**<a name="line.266"></a>
<FONT color="green">267</FONT>         * Generates a crypt(3) compatible hash using the DES algorithm.<a name="line.267"></a>
<FONT color="green">268</FONT>         *<a name="line.268"></a>
<FONT color="green">269</FONT>         * @param original<a name="line.269"></a>
<FONT color="green">270</FONT>         *            plaintext password<a name="line.270"></a>
<FONT color="green">271</FONT>         * @param salt<a name="line.271"></a>
<FONT color="green">272</FONT>         *            a two character string drawn from [a-zA-Z0-9./] or null for a random one<a name="line.272"></a>
<FONT color="green">273</FONT>         * @return a 13 character string starting with the salt string<a name="line.273"></a>
<FONT color="green">274</FONT>         * @throws IllegalArgumentException<a name="line.274"></a>
<FONT color="green">275</FONT>         *             if the salt does not match the allowed pattern<a name="line.275"></a>
<FONT color="green">276</FONT>         */<a name="line.276"></a>
<FONT color="green">277</FONT>        public static String crypt(final String original, final String salt) {<a name="line.277"></a>
<FONT color="green">278</FONT>            return crypt(original.getBytes(Charsets.UTF_8), salt);<a name="line.278"></a>
<FONT color="green">279</FONT>        }<a name="line.279"></a>
<FONT color="green">280</FONT>    <a name="line.280"></a>
<FONT color="green">281</FONT>        private static int[] body(final int schedule[], final int eSwap0, final int eSwap1) {<a name="line.281"></a>
<FONT color="green">282</FONT>            int left = 0;<a name="line.282"></a>
<FONT color="green">283</FONT>            int right = 0;<a name="line.283"></a>
<FONT color="green">284</FONT>            int t = 0;<a name="line.284"></a>
<FONT color="green">285</FONT>            for (int j = 0; j &lt; 25; j++) {<a name="line.285"></a>
<FONT color="green">286</FONT>                for (int i = 0; i &lt; 32; i += 4) {<a name="line.286"></a>
<FONT color="green">287</FONT>                    left = dEncrypt(left, right, i, eSwap0, eSwap1, schedule);<a name="line.287"></a>
<FONT color="green">288</FONT>                    right = dEncrypt(right, left, i + 2, eSwap0, eSwap1, schedule);<a name="line.288"></a>
<FONT color="green">289</FONT>                }<a name="line.289"></a>
<FONT color="green">290</FONT>                t = left;<a name="line.290"></a>
<FONT color="green">291</FONT>                left = right;<a name="line.291"></a>
<FONT color="green">292</FONT>                right = t;<a name="line.292"></a>
<FONT color="green">293</FONT>            }<a name="line.293"></a>
<FONT color="green">294</FONT>    <a name="line.294"></a>
<FONT color="green">295</FONT>            t = right;<a name="line.295"></a>
<FONT color="green">296</FONT>            right = left &gt;&gt;&gt; 1 | left &lt;&lt; 31;<a name="line.296"></a>
<FONT color="green">297</FONT>            left = t &gt;&gt;&gt; 1 | t &lt;&lt; 31;<a name="line.297"></a>
<FONT color="green">298</FONT>            final int results[] = new int[2];<a name="line.298"></a>
<FONT color="green">299</FONT>            permOp(right, left, 1, 0x55555555, results);<a name="line.299"></a>
<FONT color="green">300</FONT>            right = results[0];<a name="line.300"></a>
<FONT color="green">301</FONT>            left = results[1];<a name="line.301"></a>
<FONT color="green">302</FONT>            permOp(left, right, 8, 0xff00ff, results);<a name="line.302"></a>
<FONT color="green">303</FONT>            left = results[0];<a name="line.303"></a>
<FONT color="green">304</FONT>            right = results[1];<a name="line.304"></a>
<FONT color="green">305</FONT>            permOp(right, left, 2, 0x33333333, results);<a name="line.305"></a>
<FONT color="green">306</FONT>            right = results[0];<a name="line.306"></a>
<FONT color="green">307</FONT>            left = results[1];<a name="line.307"></a>
<FONT color="green">308</FONT>            permOp(left, right, 16, 65535, results);<a name="line.308"></a>
<FONT color="green">309</FONT>            left = results[0];<a name="line.309"></a>
<FONT color="green">310</FONT>            right = results[1];<a name="line.310"></a>
<FONT color="green">311</FONT>            permOp(right, left, 4, 0xf0f0f0f, results);<a name="line.311"></a>
<FONT color="green">312</FONT>            right = results[0];<a name="line.312"></a>
<FONT color="green">313</FONT>            left = results[1];<a name="line.313"></a>
<FONT color="green">314</FONT>            final int out[] = new int[2];<a name="line.314"></a>
<FONT color="green">315</FONT>            out[0] = left;<a name="line.315"></a>
<FONT color="green">316</FONT>            out[1] = right;<a name="line.316"></a>
<FONT color="green">317</FONT>            return out;<a name="line.317"></a>
<FONT color="green">318</FONT>        }<a name="line.318"></a>
<FONT color="green">319</FONT>    <a name="line.319"></a>
<FONT color="green">320</FONT>        private static int byteToUnsigned(final byte b) {<a name="line.320"></a>
<FONT color="green">321</FONT>            final int value = b;<a name="line.321"></a>
<FONT color="green">322</FONT>            return value &lt; 0 ? value + 256 : value;<a name="line.322"></a>
<FONT color="green">323</FONT>        }<a name="line.323"></a>
<FONT color="green">324</FONT>    <a name="line.324"></a>
<FONT color="green">325</FONT>        private static int dEncrypt(int el, final int r, final int s, final int e0, final int e1, final int sArr[]) {<a name="line.325"></a>
<FONT color="green">326</FONT>            int v = r ^ r &gt;&gt;&gt; 16;<a name="line.326"></a>
<FONT color="green">327</FONT>            int u = v &amp; e0;<a name="line.327"></a>
<FONT color="green">328</FONT>            v &amp;= e1;<a name="line.328"></a>
<FONT color="green">329</FONT>            u = u ^ u &lt;&lt; 16 ^ r ^ sArr[s];<a name="line.329"></a>
<FONT color="green">330</FONT>            int t = v ^ v &lt;&lt; 16 ^ r ^ sArr[s + 1];<a name="line.330"></a>
<FONT color="green">331</FONT>            t = t &gt;&gt;&gt; 4 | t &lt;&lt; 28;<a name="line.331"></a>
<FONT color="green">332</FONT>            el ^= SPTRANS[1][t &amp; 0x3f] | SPTRANS[3][t &gt;&gt;&gt; 8 &amp; 0x3f] | SPTRANS[5][t &gt;&gt;&gt; 16 &amp; 0x3f] |<a name="line.332"></a>
<FONT color="green">333</FONT>                    SPTRANS[7][t &gt;&gt;&gt; 24 &amp; 0x3f] | SPTRANS[0][u &amp; 0x3f] | SPTRANS[2][u &gt;&gt;&gt; 8 &amp; 0x3f] |<a name="line.333"></a>
<FONT color="green">334</FONT>                    SPTRANS[4][u &gt;&gt;&gt; 16 &amp; 0x3f] | SPTRANS[6][u &gt;&gt;&gt; 24 &amp; 0x3f];<a name="line.334"></a>
<FONT color="green">335</FONT>            return el;<a name="line.335"></a>
<FONT color="green">336</FONT>        }<a name="line.336"></a>
<FONT color="green">337</FONT>    <a name="line.337"></a>
<FONT color="green">338</FONT>        private static int[] desSetKey(final byte key[]) {<a name="line.338"></a>
<FONT color="green">339</FONT>            final int schedule[] = new int[32];<a name="line.339"></a>
<FONT color="green">340</FONT>            int c = fourBytesToInt(key, 0);<a name="line.340"></a>
<FONT color="green">341</FONT>            int d = fourBytesToInt(key, 4);<a name="line.341"></a>
<FONT color="green">342</FONT>            final int results[] = new int[2];<a name="line.342"></a>
<FONT color="green">343</FONT>            permOp(d, c, 4, 0xf0f0f0f, results);<a name="line.343"></a>
<FONT color="green">344</FONT>            d = results[0];<a name="line.344"></a>
<FONT color="green">345</FONT>            c = results[1];<a name="line.345"></a>
<FONT color="green">346</FONT>            c = hPermOp(c, -2, 0xcccc0000);<a name="line.346"></a>
<FONT color="green">347</FONT>            d = hPermOp(d, -2, 0xcccc0000);<a name="line.347"></a>
<FONT color="green">348</FONT>            permOp(d, c, 1, 0x55555555, results);<a name="line.348"></a>
<FONT color="green">349</FONT>            d = results[0];<a name="line.349"></a>
<FONT color="green">350</FONT>            c = results[1];<a name="line.350"></a>
<FONT color="green">351</FONT>            permOp(c, d, 8, 0xff00ff, results);<a name="line.351"></a>
<FONT color="green">352</FONT>            c = results[0];<a name="line.352"></a>
<FONT color="green">353</FONT>            d = results[1];<a name="line.353"></a>
<FONT color="green">354</FONT>            permOp(d, c, 1, 0x55555555, results);<a name="line.354"></a>
<FONT color="green">355</FONT>            d = results[0];<a name="line.355"></a>
<FONT color="green">356</FONT>            c = results[1];<a name="line.356"></a>
<FONT color="green">357</FONT>            d = (d &amp; 0xff) &lt;&lt; 16 | d &amp; 0xff00 | (d &amp; 0xff0000) &gt;&gt;&gt; 16 | (c &amp; 0xf0000000) &gt;&gt;&gt; 4;<a name="line.357"></a>
<FONT color="green">358</FONT>            c &amp;= 0xfffffff;<a name="line.358"></a>
<FONT color="green">359</FONT>            int j = 0;<a name="line.359"></a>
<FONT color="green">360</FONT>            for (int i = 0; i &lt; 16; i++) {<a name="line.360"></a>
<FONT color="green">361</FONT>                if (SHIFT2[i]) {<a name="line.361"></a>
<FONT color="green">362</FONT>                    c = c &gt;&gt;&gt; 2 | c &lt;&lt; 26;<a name="line.362"></a>
<FONT color="green">363</FONT>                    d = d &gt;&gt;&gt; 2 | d &lt;&lt; 26;<a name="line.363"></a>
<FONT color="green">364</FONT>                } else {<a name="line.364"></a>
<FONT color="green">365</FONT>                    c = c &gt;&gt;&gt; 1 | c &lt;&lt; 27;<a name="line.365"></a>
<FONT color="green">366</FONT>                    d = d &gt;&gt;&gt; 1 | d &lt;&lt; 27;<a name="line.366"></a>
<FONT color="green">367</FONT>                }<a name="line.367"></a>
<FONT color="green">368</FONT>                c &amp;= 0xfffffff;<a name="line.368"></a>
<FONT color="green">369</FONT>                d &amp;= 0xfffffff;<a name="line.369"></a>
<FONT color="green">370</FONT>                int s = SKB[0][c &amp; 0x3f] | SKB[1][c &gt;&gt;&gt; 6 &amp; 0x3 | c &gt;&gt;&gt; 7 &amp; 0x3c] |<a name="line.370"></a>
<FONT color="green">371</FONT>                        SKB[2][c &gt;&gt;&gt; 13 &amp; 0xf | c &gt;&gt;&gt; 14 &amp; 0x30] |<a name="line.371"></a>
<FONT color="green">372</FONT>                        SKB[3][c &gt;&gt;&gt; 20 &amp; 0x1 | c &gt;&gt;&gt; 21 &amp; 0x6 | c &gt;&gt;&gt; 22 &amp; 0x38];<a name="line.372"></a>
<FONT color="green">373</FONT>                final int t = SKB[4][d &amp; 0x3f] | SKB[5][d &gt;&gt;&gt; 7 &amp; 0x3 | d &gt;&gt;&gt; 8 &amp; 0x3c] | SKB[6][d &gt;&gt;&gt; 15 &amp; 0x3f] |<a name="line.373"></a>
<FONT color="green">374</FONT>                        SKB[7][d &gt;&gt;&gt; 21 &amp; 0xf | d &gt;&gt;&gt; 22 &amp; 0x30];<a name="line.374"></a>
<FONT color="green">375</FONT>                schedule[j++] = (t &lt;&lt; 16 | s &amp; 0xffff);<a name="line.375"></a>
<FONT color="green">376</FONT>                s = s &gt;&gt;&gt; 16 | t &amp; 0xffff0000;<a name="line.376"></a>
<FONT color="green">377</FONT>                s = s &lt;&lt; 4 | s &gt;&gt;&gt; 28;<a name="line.377"></a>
<FONT color="green">378</FONT>                schedule[j++] = s;<a name="line.378"></a>
<FONT color="green">379</FONT>            }<a name="line.379"></a>
<FONT color="green">380</FONT>    <a name="line.380"></a>
<FONT color="green">381</FONT>            return schedule;<a name="line.381"></a>
<FONT color="green">382</FONT>        }<a name="line.382"></a>
<FONT color="green">383</FONT>    <a name="line.383"></a>
<FONT color="green">384</FONT>        private static int fourBytesToInt(final byte b[], int offset) {<a name="line.384"></a>
<FONT color="green">385</FONT>            int value = byteToUnsigned(b[offset++]);<a name="line.385"></a>
<FONT color="green">386</FONT>            value |= byteToUnsigned(b[offset++]) &lt;&lt; 8;<a name="line.386"></a>
<FONT color="green">387</FONT>            value |= byteToUnsigned(b[offset++]) &lt;&lt; 16;<a name="line.387"></a>
<FONT color="green">388</FONT>            value |= byteToUnsigned(b[offset++]) &lt;&lt; 24;<a name="line.388"></a>
<FONT color="green">389</FONT>            return value;<a name="line.389"></a>
<FONT color="green">390</FONT>        }<a name="line.390"></a>
<FONT color="green">391</FONT>    <a name="line.391"></a>
<FONT color="green">392</FONT>        private static int hPermOp(int a, final int n, final int m) {<a name="line.392"></a>
<FONT color="green">393</FONT>            final int t = (a &lt;&lt; 16 - n ^ a) &amp; m;<a name="line.393"></a>
<FONT color="green">394</FONT>            a = a ^ t ^ t &gt;&gt;&gt; 16 - n;<a name="line.394"></a>
<FONT color="green">395</FONT>            return a;<a name="line.395"></a>
<FONT color="green">396</FONT>        }<a name="line.396"></a>
<FONT color="green">397</FONT>    <a name="line.397"></a>
<FONT color="green">398</FONT>        private static void intToFourBytes(final int iValue, final byte b[], int offset) {<a name="line.398"></a>
<FONT color="green">399</FONT>            b[offset++] = (byte) (iValue &amp; 0xff);<a name="line.399"></a>
<FONT color="green">400</FONT>            b[offset++] = (byte) (iValue &gt;&gt;&gt; 8 &amp; 0xff);<a name="line.400"></a>
<FONT color="green">401</FONT>            b[offset++] = (byte) (iValue &gt;&gt;&gt; 16 &amp; 0xff);<a name="line.401"></a>
<FONT color="green">402</FONT>            b[offset++] = (byte) (iValue &gt;&gt;&gt; 24 &amp; 0xff);<a name="line.402"></a>
<FONT color="green">403</FONT>        }<a name="line.403"></a>
<FONT color="green">404</FONT>    <a name="line.404"></a>
<FONT color="green">405</FONT>        private static void permOp(int a, int b, final int n, final int m, final int results[]) {<a name="line.405"></a>
<FONT color="green">406</FONT>            final int t = (a &gt;&gt;&gt; n ^ b) &amp; m;<a name="line.406"></a>
<FONT color="green">407</FONT>            a ^= t &lt;&lt; n;<a name="line.407"></a>
<FONT color="green">408</FONT>            b ^= t;<a name="line.408"></a>
<FONT color="green">409</FONT>            results[0] = a;<a name="line.409"></a>
<FONT color="green">410</FONT>            results[1] = b;<a name="line.410"></a>
<FONT color="green">411</FONT>        }<a name="line.411"></a>
<FONT color="green">412</FONT>    <a name="line.412"></a>
<FONT color="green">413</FONT>    }<a name="line.413"></a>




























































</PRE>
</BODY>
</HTML>
